package com.buanalintas.sandals.pos.job;

import com.buanalintas.bynga.Persistence;
import com.buanalintas.bynga.Utility;
import com.buanalintas.bynga.entities.TransactionNotifications;
import com.buanalintas.sandals.pos.entities.PosTransactionReceipt;
import java.util.Date;
import java.util.List;
import java.util.TimerTask;
import javax.persistence.EntityManager;
import javax.persistence.Query;

public class Giro extends TimerTask {

    public Giro() {
    }

    @Override
    public void run() {
//        EntityManager em = Persistence.getEntityManager();
//        em.getTransaction().begin();
//        Date start = Utility.getTimestamp();
//        Date end = Utility.getTimestamp();
//        start.setTime(end.getTime() - 86400000 * 3);
//        Query query = em.createQuery("SELECT t FROM PosTransactionReceipt t WHERE t.receiptFirstGiroDate BETWEEN :start AND :end ");
//        query.setParameter("start", start);
//        query.setParameter("end", end);
//        List<PosTransactionReceipt> receipts = query.setHint(Persistence.REFRESH_HINT, true).getResultList();
//
//        for (PosTransactionReceipt receipt : receipts) {
//            if ("1".equals(receipts)) {
//                TransactionNotifications notification = new TransactionNotifications();
//                notification.setNotificationsUserId(receipt.getReceiptUserId());
//                notification.setNotificationsText("Reminder Giro-1");
//                notification.setNotificationsContent("Pembayaran Giro-1");
//                notification.setNotificationsLink(receipt.getReceiptNumber());
//                notification.setNotificationsView(start);
//                notification.setNotificationsClick(start);
//                em.persist(notification);
//
//            } else {
//                TransactionNotifications notification = new TransactionNotifications();
//                notification.setNotificationsUserId(receipt.getReceiptUserId());
//                notification.setNotificationsText("Reminder Giro-2");
//                notification.setNotificationsContent("Pembayaran Giro-2");
//                notification.setNotificationsLink(receipt.getReceiptNumber());
//                notification.setNotificationsView(start);
//                notification.setNotificationsClick(start);
//                em.persist(notification);
//            }
//        }
//        em.getTransaction().commit();
    }
//    public static void main(String...args) {
//        new Thread(new Giro()).start();
//    }
}
